home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UArticleCmds.cp < prev    next >
Encoding:
Text File  |  1994-03-12  |  4.4 KB  |  206 lines  |  [TEXT/MPS ]

  1. // Copyright © 1992 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // TArticleCmds.cp
  3.  
  4. #include "UArticleCmds.h"
  5. #include "UArticleListView.h"
  6. #include "FileTools.h"
  7. #include "UGroupDoc.h"
  8. #include "UPrefsDatabase.h"
  9. #include <ErrorGlobals.h>
  10.  
  11. #include <RsrcGlobals.h>
  12.  
  13. #include <UGridView.h>
  14.  
  15. #include <ToolUtils.h>
  16.  
  17. #pragma segment MyArticle
  18.  
  19.  
  20. ///---------------------------------------------------------------------
  21. TShowDiscJunkCommand::TShowDiscJunkCommand()
  22. {
  23. }
  24.  
  25. pascal void TShowDiscJunkCommand::Initialize()
  26. {
  27.     inherited::Initialize();
  28.     fArticleListView = nil;
  29.     fIndex = nil;
  30. }
  31.  
  32. void TShowDiscJunkCommand::IShowDiscJunkCommand(TArticleListView *articleListView, long index)
  33. {
  34.     inherited::ICommand(cShowDiscJunkCommand, nil, false, false, nil);
  35.     fArticleListView = articleListView;
  36.     fIndex = index;
  37. }
  38.  
  39. pascal void TShowDiscJunkCommand::Free()
  40. {
  41.     fArticleListView = nil;
  42.     fIndex = nil;
  43.     inherited::Free();
  44. }
  45.  
  46. pascal void TShowDiscJunkCommand::DoIt()
  47. {
  48.     fArticleListView->SetDiscussionDisplayed(fIndex);
  49. }
  50.  
  51.  
  52. //---------------------------------------------------------------------
  53. TCopyArticleTextCommand::TCopyArticleTextCommand()
  54. {
  55. }
  56.  
  57. pascal void TCopyArticleTextCommand::ICopyArticleTextCommand(TArticleListView *articleListView, Boolean asQuote, Boolean addHeader)
  58. {
  59.     inherited::ICommand(cCopy, nil, false, false, nil);
  60.     fArticleListView = articleListView;
  61.     fAsQuote = asQuote;
  62.     fAddHeader = addHeader;
  63. }
  64.  
  65. pascal void TCopyArticleTextCommand::DoIt()
  66. {
  67.     Handle h = nil;
  68.     VOLATILE(h);
  69.     FailInfo fi;
  70.     if (fi.Try())
  71.     {
  72.         h = fArticleListView->GetSelectionAsTextForClipboard(fAsQuote, fAddHeader);
  73.         ZeroScrap();
  74.         HLock(h);
  75.         FailOSErr(gClipboardMgr->PutDeskScrapData('TEXT', h));
  76.         h = DisposeIfHandle(h);
  77.         fi.Success();
  78.     }
  79.     else // fail
  80.     {
  81.         h = DisposeIfHandle(h);
  82.         fi.ReSignal();
  83.     }
  84. }
  85. //---------------------------------------------------------------------
  86. TUpdateArticleViewCommand::TUpdateArticleViewCommand()
  87. {
  88. }
  89.  
  90. pascal void TUpdateArticleViewCommand::Initialize()
  91. {
  92.     inherited::Initialize();
  93.     fArticleListView = nil;
  94. }
  95.  
  96. void TUpdateArticleViewCommand::IUpdateArticleViewCommand(TArticleListView *alv, ArticleShowType whatToShow)
  97. {
  98.     inherited::ICommand(cUpdateArticleListCommand, nil, false, false, nil);
  99.     fArticleListView = alv;
  100.     fWhatToShow = whatToShow;
  101. }
  102.  
  103. pascal void TUpdateArticleViewCommand::Free()
  104. {
  105.     inherited::Free();
  106. }
  107.  
  108. pascal void TUpdateArticleViewCommand::DoIt()
  109. {
  110.     fArticleListView->DoTheUpdateList(fWhatToShow);
  111. }
  112. //---------------------------------------------------------------------
  113. TStoreNotesCommand::TStoreNotesCommand()
  114. {
  115. }
  116.  
  117. pascal void TStoreNotesCommand::Initialize()
  118. {
  119.     inherited::Initialize();
  120.     fArticleListView = nil;
  121.     fFile = nil;
  122.     fPBP = nil;
  123. }
  124.  
  125. void TStoreNotesCommand::IStoreNotesCommand(TArticleListView *alv)
  126. {
  127.     inherited::ICommand(cStoreNotes, nil, false, false, nil);
  128.     fArticleListView = alv;
  129.     fPBP = (ParamBlockRec*)NewPermPtr(sizeof(ParamBlockRec));
  130. }
  131.  
  132. pascal void TStoreNotesCommand::Free()
  133. {
  134.     FreeIfObject(fFile); fFile = nil; // closes file
  135.     DisposeIfPtr(Ptr(fPBP)); fPBP = nil;
  136.     inherited::Free();
  137. }
  138.  
  139. pascal void TStoreNotesCommand::DoIt()
  140. {
  141.     FailInfo fi;
  142.     if (fi.Try())
  143.     {
  144.         OpenFile();
  145.         StoreQuote();
  146.         fFile->CloseFile();
  147.         fi.Success();
  148.     }
  149.     else // failure
  150.     {
  151.         FailNewMessage(fi.error, fi.message, messageSaveNotes);
  152.     }
  153. }
  154.  
  155. void TStoreNotesCommand::OpenFile()
  156. {
  157.     FailInfo fi;
  158.     if (fi.Try())
  159.     {
  160.         if (!gPrefs->PrefExists('FNot'))
  161.             FailOSErr(errNoNoteFolder);
  162.         if (!gPrefs->PrefExists('EDsi'))
  163.             FailOSErr(errNoEditor);
  164.         OSType signature = gPrefs->GetSignaturePrefs('EDsi');
  165.         fFile = NewFile('TEXT', signature,
  166.             kUsesDataFork, noResourceFork, !kDataOpen, !kRsrcOpen);
  167.         fFile->SetPermissions(fsRdWrPerm, fsRdWrPerm);
  168.         FSSpec spec;
  169.         gPrefs->GetDirAliasPrefs('FNot', spec);
  170.         CStr255 dotName;
  171.         fArticleListView->fDoc->GetGroupDotName(dotName);
  172.         GoGroupFile(dotName, spec);
  173.         fFile->Specify(spec);
  174.         if (!FileExist(fFile))
  175.             FailOSErr(fFile->CreateFile());
  176.         FailOSErr(fFile->OpenFile());
  177.         FailOSErr(fFile->SetDataMark(0, fsFromLEOF));
  178.         fi.Success();
  179.     }
  180.     else // failure
  181.     {
  182.         FailNewMessage(fi.error, fi.message, messageOpenNotesFile);
  183.     }
  184. }
  185.  
  186. void TStoreNotesCommand::StoreQuote()
  187. {
  188.     Handle h = nil;
  189.     VOLATILE(h);
  190.     FailInfo fi;
  191.     if (fi.Try())
  192.     {
  193.         h = fArticleListView->GetSelectionAsQuoteText(false, true, kNoteQuoteTemplate);
  194.         HLock(h);
  195.         long len = GetHandleSize(h);
  196.         WriteASyncToFile(*fPBP, fFile, *h, len);
  197.         HUnlock(h);
  198.         fi.Success();
  199.     }
  200.     else // fail
  201.     {
  202.         h = DisposeIfHandle(h);
  203.         fi.ReSignal();
  204.     }
  205. }
  206.